<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 2.17</title>
</head>

<body>
<?php
	if(isset($_POST['sobd']) && isset($_POST['sokt']))
	{
		$sobd=	$_POST['sobd'];
		$sokt=	$_POST['sokt'];
		$tichcacso=1;
		if($sobd<=$sokt)
		{
			//tinh tong cac so
			for($i=$sobd;$i<=$sokt;$i++)
				$tongcacso+=$i;
			//tinh tich cac so
			if($sobd==0 ||$sokt==0)
				$tichcacso=0;
			else
			{
				for($i=$sobd;$i<=$sokt;$i++)
					$tichcacso*=$i;
			}
			//tinh tong cac so chan trong day so
			for($i=$sobd;$i<=$sokt;$i++)
				if($i%2==0)
					$tongcacsochan+=$i;
				else
					$tongcacsole+=$i;
		}
		else
			$thongbao="Số kết thúc phải lớn hơn số bắt đầu";
	}
?>
<form id="form1" name="form1" method="post" action="Bai2_17.php">
  <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td colspan="2" bgcolor="#FFCCCC" style="font-weight: bold; font-style: italic; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; text-align: center; color: #FFF;">TÍNH TOÁN TRÊN DÃY SỐ</td>
    </tr>
    <tr>
      <td bgcolor="#FF99FF">Giới hạn của dãy số:</td>
      <td bgcolor="#FFFFFF">Số bắt đầu: 
        <input name="sobd" type="text" id="sobd" value="<?php echo $_POST['sobd'];?>" size="5" />
Số kết thúc: 
<input name="sokt" type="text" id="sokt" value="<?php echo $_POST['sokt'];?>" size="5" /></td>
    </tr>
    <tr>
      <td bgcolor="#FF99FF" style="font-weight: bold; color: #00F;">Kết quả:</td>
      <td bgcolor="#FF99FF">&nbsp;</td>
    </tr>
    <tr>
      <td bgcolor="#FF99FF">Tổng các số:</td>
      <td bgcolor="#FF99FF"><input name="tongcacso" type="text" disabled="disabled" id="tongcacso" style="background-color:#FCF" value="<?php echo $tongcacso; ?>" /></td>
    </tr>
    <tr>
      <td bgcolor="#FF99FF">Tích các số:</td>
      <td bgcolor="#FF99FF"><input name="tichcacso" type="text" disabled="disabled" id="tichcacso" style="background-color:#FCF" value="<?php echo $tichcacso; ?>" /></td>
    </tr>
    <tr>
      <td bgcolor="#FF99FF">Tổng các số chẵn:</td>
      <td bgcolor="#FF99FF"><input name="tongcacsochan" type="text" disabled="disabled" id="tongcacsochan" style="background-color:#FCF" value="<?php echo $tongcacsochan; ?>" /></td>
    </tr>
    <tr>
      <td bgcolor="#FF99FF">Tổng các số lẻ:</td>
      <td bgcolor="#FF99FF"><input name="tongcacsole" type="text" disabled="disabled" id="tongcacsole" style="background-color:#FCF" value="<?php echo $tongcacsole; ?>" /></td>
    </tr>
    <tr>
      <td colspan="2" bgcolor="#FF99FF" style="text-align: center"><input style="background-color:#F96" type="submit" name="submit" id="submit" value="Tính toán" /></td>
    </tr>
  </table>
</form>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td style="text-align: center"><label style="text-align: center; color: #F00; font-weight: bold;"><?php echo $thongbao;?></label></td>
  </tr>
</table>

</body>
</html>